package com.cskaoyan.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//@Component
public class CustomHandlerExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler, Exception exception) {
        //只想对算术异常做处理 → 对特定的异常做个性化的处理
        if (exception instanceof ArithmeticException) {

            return new ModelAndView("/exception.jsp");
        }
        //如果想要响应json，可以不？
        //httpServletResponse
        return null;

    }
}
